﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;  // for exe path of application
using MySql.Data.MySqlClient;     // for connection with database

namespace PayPalApp
{
    class DataHelper
    {
        private MySqlConnection connection;

        /* CONSTRUCTOR*/
        public DataHelper()
        {
            String connectionInfo = "server=athena01.fhict.local;" +
                             "database=dbi269964;" + // your database name
                             "user id=dbi269964;" + // your user id
                             "password=ztauJSorfR;" + // your password
                             "connect timeout=30;";
            connection = new MySqlConnection(connectionInfo);

        }

        public int updateAccount(String account, Double amount)
        {
            String visitorId = Convert.ToString(account);
            String sql = "UPDATE EVENT_ACCOUNT SET MoneyDeposited=MoneyDeposited+'" + amount + "'  WHERE Visitor_id='" + visitorId + "'";
            MySqlCommand command = new MySqlCommand(sql, connection);

            try
            {
                connection.Open();
                int nrOfRecordsChanged = command.ExecuteNonQuery();
                return nrOfRecordsChanged;
            }
            catch
            {
                return -1; //which means the try-block was not executed succesfully, so  . . .
            }
            finally
            {
                connection.Close();
            }
        }
    }
}
